package exceptiondemo;

import java.util.Scanner;

public class ExceptionDemo6 {
    public static void main(String[] args) {
        // 目标：掌握异常的处理方案2：捕获异常对象，尝试重新修复
        //接收用户的一个定价
        System.out.println("程序开始");
        while (true) {
            try {
                double price = getPrice();
                System.out.println("商品的价格是：" + price);
                break;
            } catch (Exception e) {
                System.out.println("你输入的价格有误，请重新输入！");
            }
        }
        System.out.println("程序结束");
    }

    public static double getPrice() {
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入商品定价：");
        double price = sc.nextDouble();
        return price;
    }
}
